package com.group9.handinhand.controller.form;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.List;

import com.group9.handinhand.service.so.RequestSO;

public class RequestCreateForm {
	
	RequestSO request = new RequestSO();
	String selectedTags;
	String endingDay;
	String endingHour;
	
	public RequestSO getRequest() {
		return request;
	}

	public void setRequest(RequestSO request) {
		this.request = request;
	}
	
	public String getSelectedTags() {
		return selectedTags;
	}

	public void setSelectedTags(String selectedTags) {
		this.selectedTags = selectedTags;
	}

	public String getEndingDay() {
		return endingDay;
	}

	public void setEndingDay(String endingDay) {
		this.endingDay = endingDay;
	}

	public String getEndingHour() {
		return endingHour;
	}

	public void setEndingHour(String endingHour) {
		this.endingHour = endingHour;
	}

	@Override
	public String toString() {
		return "RequestCreateForm [request=" + request + ", selectedTags="
				+ selectedTags + ", endingDay=" + endingDay + ", endingHour="
				+ endingHour + "]";
	}

	public void setEndDate() {
		SimpleDateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy HH:mm");
		
		String endingDate = endingDay + " " + endingHour;
		
		try {
			request.setExpirationDate(dateFormat.parse(endingDate));
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}
	/**
	 * A getter method.
	 * @return the list of the selected tags as a list
	 */
	public List<String> getSelectedTagsAsList() {
		String[] tags = selectedTags.split(",");
		return Arrays.asList(tags);
	}

}
